Python to complete the business code, you can even ask a web designer to help you with the rest. Template system is to help you achieve business and performance separation.
Let's finish the first template (fileapp/templates/index.html):
As you can see, we've just written an ordinary HTML page, and the only difference to HTML is that there are some dynamic content placeholders with {{...}}}.
Now let's look at how the template is handle
following command:
Copy Code code as follows:
Flask/bin/pip Install Flask-whooshalchemy
Configuration
Configuring Flask-whooshalchemy Ash is often simple. All we need to do is tell the extended Full-text search database name (fileconfig.py):Whoosh_base = Os.path.join (basedir, ' search.db ')modifying Modules
When combining Flask-whooshalchemy and flask-sqlalchemy, we need to be indexed when the appropriate module class (fileapp
= ADMINS [0], recipients = ADMINS) >>> Msg. body = 'text body' >>> Msg.html = ' >>> Mail. send (msg)
The above Code uses the first mailbox as the sender to send an email to all the mailboxes according to the list of email addresses configured in inconfig. py. The email content is displayed in two formats: Text and html, and you can see which format depends on your mail client.
How simple and small! You can integrate it into your application now.
Email framework
Now we can write a help
separation of business logic and performance, your website structure will be better organized. Don't believe it. If you use python to complete the business code, you can even ask a website designer to help you complete the rest. The template system separates your business from your performance.
Let's complete the first template (fileapp/templates/index.html ):
?
1 2 3 4 5 6 7 8
As you can see, we just wrote a com
simply, this is the 2 configuration items that flask-wtf need to use. Csrf_enabled configuration enables cross-site request attack protection, and in most cases you need to turn on this feature to make your app more secure.
Secret_key settings are valid when CSRF is enabled, which generates an encrypted token to be used for form validation, and you want to make sure that the key is complex enough not to be simply inferred.
Now this configuration file is basically available. Project creation com
This article mainly introduces how to implement the paging function in the Python Flask framework. the example in this article is implemented based on a blog. For more information, see
Submission of Blog Posts
Let's start with something simple. A user must submit a new post form on the homepage.
First, we define a single-domain form object (fileapp/forms. py ):
class PostForm(Form): post = TextField('post', validators = [Required()])
Next, we add
following command to install Windows:
The code is as follows:
Flask \ Scripts \ pip install Flask-WhooshAlchemy
Other users use the following command to install the SDK:
The code is as follows:
Flask/bin/pip install Flask-WhooshAlchemy
Configuration
It is often easy to configure Flask-WhooshAlchemy. We only need to tell the name of the extended full-text retrieval database (fileconfig. py ): WHOOSH_BASE = OS. path. join (basedir, 'search. db ')Modify Module
When combining Flask-WhooshAlc
the business code, you can even ask a website designer to help you complete the rest. The template system separates your business from your performance.
Let's complete the first template (fileapp/templates/index.html ):
As you can see, we just wrote a common HTML page. The only difference with HTML is that it contains some dynamic content placeholders consisting.
Now let's take a look at how the view function processes this template (
into your application now.
Email framework
Now we can write a help function to send emails. This is a general version of the above test. We put this function into a new original file for mail support (fileapp/emails. py ):
from flask.ext.mail import Messagefrom app import mail def send_email(subject, sender, recipients, text_body, html_body): msg = Message(subject, sender, recipients) msg.body = text_body msg.html = html_body mail.send(msg)
The Mail
list of mailbox addresses configured in inconfig.py. The message content is rendered in text and HTML two formats, and you can see which format depends on your mail client.
How simple and small! You can fully integrate it into your application right now.
Message Frame
We can now write a help function to send the message. This is the test of a generic version of the above test. We put this function into a new original file as a mail support (fileapp
-guess '
Quite simply, this is the 2 configuration items that FLASK-WTF needs to use. Csrf_enabled configuration enables cross-station request attack protection, which you need to turn on in most cases, which makes your application more secure.
The Secret_key setting is valid when CSRF is enabled, which generates an encrypted token for form validation, and you want to make sure that the key is complex enough not to be simply inferred.
The configuration file is now basically available. Pr
exception occurs, Flask generates a 500 page.
Although this is better, there are still two problems. First, the problem of beautification: the default 500 page is ugly. The second problem is more important. When the user fails to perform operations, we cannot get the error message because the error is handled silently in the background. Fortunately, there is a simple way to deal with these two problems.
Custom HTTP Error handling program
Flask provides a mechanism for applications to install th
structure will be better organized. Don't believe it, if you've done your business code with Python, you can even ask a web designer to help you with the rest. The template system is to help you achieve separation of business and performance.
Let's complete the first template (fileapp/templates/index.html):
{{title}}-Microblog Hello, {{user.nickname}}!
As you can see, we just wrote a normal HTML page, the only thing that is different from HT
submission of Blog posts
Let's start with the simple. There must be a form on the home page where the user submits a new post.
First we define a single-domain form object (fileapp/forms.py):
Class Postform (Form): post = TextField (' post ', validators = [Required ()])
Below, we add this form to the template (fileapp/templates/index.html):
{% extends "base.html"%} {% block content%}Hi, {{g.user.nic
users are installed with the following command:
Copy the Code code as follows:Flask/bin/pip Install Flask-whooshalchemy
Configuration
Configuring Flask-whooshalchemy Ash is often simple. All we need to do is tell the extended full-text retrieval database name (fileconfig.py):Whoosh_base = Os.path.join (basedir, ' search.db ')modifying modules
When combining Flask-whooshalchemy and flask-sqlalchemy, we need to be indexed in the appropriate module class (fi
-WhooshAlchemy
Other users use the following command to install the SDK:
Copy codeThe Code is as follows: flask/bin/pip install Flask-WhooshAlchemy
Configuration
It is often easy to configure Flask-WhooshAlchemy. We only need to tell the name of the extended full-text Retrieval Database (fileconfig. py ):WHOOSH_BASE = OS. path. join (basedir, 'search. db ')Modify Module
When combining Flask-WhooshAlchemy and Flask-SQLAlchemy, We need to specify which data needs to be indexed in the appropriate m
Tutorial on implementing the paging function in the Python Flask framework
This article mainly introduces how to implement the paging function in the Python Flask framework. The example in this article is implemented based on a blog. For more information, see
Submission of Blog Posts
Let's start with something simple. A user must submit a new post form on the homepage.
First, we define a single-domain form object (fileapp/forms. py ):
?
1
Saves the world
If you keep your business logic and performance separate, your site structure will be better organized. Don't believe it, if you're using Python to complete the business code, you can even ask a web designer to help you with the rest. Template system is to help you achieve business and performance separation.
Let's finish the first template (fileapp/templates/index.html):
?
1 2 3 4 5 6 7 8
As you can see
The submission of Blog posts
Let's start with the simple. There must be a form on the home page where a user submits a new post.
First we define a single domain form object (fileapp/forms.py):
Class Postform (Form):
post = TextField (' post ', validators = [Required ()])
Next, we add this form to template (fileapp/templates/index.html):
So far nothing new, as you can see, we
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.